import { createSSRApp } from 'vue'
import App from './App.vue'
import uviewPlus from 'uview-plus'
import router from './router'
import pinia from './store'
import { getDictLabel } from './utils/dict'
import { isNull, parseTime } from './utils'
import './style/main.scss'
import formValidate from './utils/formValidate'
import Navbar from './components/Navbar/navbar.vue'
import uniTools from '@/utils/uniTools'
import svg from './components/svg/svg.vue'
//  #ifdef H5
import VueBMap, { initBMapApiLoader } from 'vue-bmap-gl'
import 'vue-bmap-gl/dist/style.css'
// #endif
export function createApp() {
  const app = createSSRApp(App)
  app.use(pinia)
  app.use(router)
  pinia.init()
  //  #ifdef H5
  initBMapApiLoader({
    ak: '6C45Mk02tovos4GSlTqp0Vptp8MZjQv7',
    plugins: 'Lushu,TrackAnimation'
  })
  app.use(VueBMap)
  // #endif
  app.use(uviewPlus)

  pinia.dictStore.initDict()
  app.component('Navbar', Navbar)
  app.component('Dsvg', svg)
  // 定义字典全局方法
  app.config.globalProperties.dictList = function (code) {
    return pinia.dictStore.dicts[code]
  }
  // 字典解析
  app.config.globalProperties.dictLabel = getDictLabel
  // 时间解析
  app.config.globalProperties.parseTime = parseTime
  // 表单校验
  app.config.globalProperties.formValidate = formValidate
  // pinia
  app.config.globalProperties.$store = pinia
  // 判空函数
  app.config.globalProperties.isNull = isNull

  app.config.globalProperties.$uni = uniTools
  // 删除按钮配置
  app.config.globalProperties.deleteOption = [{
    text: '删除',
    style: {
      backgroundColor: '#ff3c3c'
    }
  }]
  return {
    app
  }
}
